package com.zhl.service_.impl;

import com.zhl.dao_.LinkMapper;
import com.zhl.entity.Link;
import com.zhl.service_.LinkService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by Administrator on 2018/11/5.
 */
@Service
public class LinkServiceImpl implements LinkService {

    @Autowired
    private LinkMapper linkMapper;

    @Override
    public List<Link> linkList(int pageNumber, int pageSize) {
        //TODO 分页问题待解决
        Example example = new Example(Link.class);
        List<Link> links = linkMapper.selectByExampleAndRowBounds(example, new RowBounds(pageNumber, pageSize));
//        List<Link> links = linkMapper.linkList(pageNumber, pageSize);
        return links;
    }

    @Override
    public Link querylinkById(int id) {
        Example example = new Example(Link.class);
        example.createCriteria().andEqualTo("id",id);
        Link link = linkMapper.selectOneByExample(example);
//        Link link = linkMapper.querylinkById(id);
        return link;
    }

    @Override
    public int totalCount() {
        return linkMapper.totalCount();
    }

    @Override
    public int addLink(Link link) {
        return linkMapper.addLink(link);
    }

    @Override
    public int updateLink(Link link) {
        return linkMapper.updateLink(link);
    }

    @Override
    public int deleteLink(int id) {
        return linkMapper.deleteLink(id);
    }
}
